package leetcode_301_400;

import node.ListNode;

import javax.crypto.Cipher;
import java.time.OffsetDateTime;

public class LeeCode_328 {
    public static void main(String[] args) {
        System.out.println(oddEvenList(new ListNode(1, new ListNode(2,
                new ListNode(3, new ListNode(4))))));
    }

    private static ListNode oddEvenList(ListNode head) {
        ListNode c1 = head;
        if (c1 == null) {
            return head;
        }
        ListNode to = head.next;
        ListNode c2 = head.next;
        if (c2 == null)
            return head;
        ListNode cur1 = head;
        ListNode cur2 = head.next;
        boolean flag1 = true, flag2 = true;
        while (flag1 && flag2) {
            c1 = c1.next;
            if (c1 == null) {
                flag1 = false;
            } else {
                c1 = c1.next;
            }
            if (c1 == null){
                flag1 = false;
            }
            c2 = c2.next;
            if (c2 == null) {
                flag2 = false;
            } else {
                c2 = c2.next;
            }
            if (c2 == null){
                flag2 = false;
            }
            cur1.next = c1;
            cur1 = cur1.next;

            cur2.next = c2;
            cur2 = cur2.next;

        }
        ListNode cur = head;
        while (cur.next != null){
            cur = cur.next;
        }
        cur.next = to;
        return head;
    }
}
